/*
 * bsp_FatFS.h
 *
 *  Created on: 2016-1-13
 *      Author: ZhangYu
 *
 *  this BSP Support the API for fatFS operation
 */

#ifndef BSP_FATFS_H_
#define BSP_FATFS_H_

#include "ff.h"
/**
 * @brief  Default truncate buffer size in bytes
 * @note   If you have in plan to truncate from beginning large files a lot of times,
 *         then you should think about increasing this value as far as possible.
 *         With larger buffer size you will get faster response with truncating.
 */
#ifndef FATFS_TRUNCATE_BUFFER_SIZE
#define FATFS_TRUNCATE_BUFFER_SIZE	256
#endif


extern FATFS fatFS;
extern FATFS *pCurFS;
extern DIR   curDir;
extern FIL   curFile;
/*******************************************************************************
* Description    : mount the FatFS to the system
*******************************************************************************/
FRESULT BSP_FS_Mount(uint8_t DrvID);

/*******************************************************************************
* Description    : unmount the FatFS to the system
*******************************************************************************/
FRESULT BSP_FS_Unmount(uint8_t DrvID);

/*******************************************************************************
* Description    : get the current Driver Name
*******************************************************************************/
const char* BSP_FS_GetCurDrvName(void);

/**
 * @brief  Gets SDCARD drive size and free space
 */
FRESULT BSP_FS_GetCurDriveSize(uint32_t* total, uint32_t* free);

/**
 * @brief  Truncates beginning of file
 *
 * Example:
 *	- You have a file, its content is: "abcdefghijklmnoprstuvwxyz",
 *	- You want to truncate first 5 bytes,
 *	- Call @ref TM_FATFS_TruncateBeginning(&opened_file, 5);
 *	- You will get new file data: "fghijklmnoprstuvwxyz"

 * @param  *fil: Pointer to already opened file
 * @param  index: Number of characters that will be truncated from beginning
 * @note   If index is more than file size, everything will be truncated, but file will not be deleted
 * @retval FRESULT struct members. If everything ok, FR_OK is returned
 */
FRESULT BSP_FS_TruncateBeginning(FIL* fil, uint32_t index);
/**************************************************************************************
FatFS operate API
**************************************************************************************/
FRESULT BSP_FS_FatCreateDir(uint8_t *dir);
FRESULT BSP_FS_FatWriteFile(uint8_t *fname, uint8_t *pBuf, uint16_t len);
FRESULT BSP_FS_FatReadFile(uint8_t *fname, uint8_t *pBuf, uint16_t readlen, uint64_t pos);

#endif /* BSP_FATFS_H_ */
